<template>
  <el-form
    v-loading="loading"
    :model="ruleForm"
    status-icon
    :rules="rules"
    ref="ruleForm"
    label-width="100px"
    class="demo-ruleForm">
    <el-form-item label="参数名称" prop="paramName">
      <el-input  v-model="ruleForm.paramName" ></el-input>
    </el-form-item>
    <el-form-item label="参数键" prop="paramKey">
      <el-input  v-model="ruleForm.paramKey" ></el-input>
    </el-form-item>
    <el-form-item label="参数值" prop="paramValue">
      <el-input  v-model="ruleForm.paramValue" ></el-input>
    </el-form-item>
    <el-form-item label="备注" prop="remark">
      <el-input  v-model="ruleForm.remark" ></el-input>
    </el-form-item>
    <el-form-item style="margin-top: 40px;margin-left: -28px">
      <el-button type="primary" @click="submitForm('ruleForm')" style="width: 320px;height: 41px;">提交</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import { ElMessage } from 'element-plus'

export default {
  name: 'DataAdd',
  data(){
    return{
      ruleForm:{},
      loading:false,
      rules:{
        paramName: [
          { required: true, message: '请输入参数名称', trigger: 'blur' }
        ],
        paramKey: [
          { required: true, message: '请输入参数键', trigger: 'blur' }
        ],
        paramValue: [
          { required: true, message: '请输入参数值', trigger: 'blur' }
        ]
      }
    }
  },
  methods:{
    //提交数据
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true
          this.$http.post('/api/param',this.ruleForm).then(res => {
            this.loading = false
            ElMessage({
              type: 'success',
              showClose: true,
              message: res.data.message,
            })
            //触发事件
            this.$emit('tao')
          }).catch(() => this.loading = false)
        } else {
          console.log('error submit!!')
          return false
        }
      })
    },
  }
}
</script>

<style scoped>

</style>
